home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2005 March / Macworld CD March 2005 - Marathon Trilogy.iso / Shareware World / iPod / iPodderX.sit / iPodderX / iPodderX.app / Contents / Resources / DownloaderFeedback.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2005-01-07  |  3.5 KB  |  91 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.3)
  3.  
  4. from time import time
  5.  
  6. class DownloaderFeedback:
  7.     
  8.     def __init__(self, choker, add_task, statusfunc, upfunc, downfunc, uptotal, downtotal, remainingfunc, leftfunc, file_length, finflag, interval, spewflag):
  9.         self.choker = choker
  10.         self.add_task = add_task
  11.         self.statusfunc = statusfunc
  12.         self.upfunc = upfunc
  13.         self.downfunc = downfunc
  14.         self.uptotal = uptotal
  15.         self.downtotal = downtotal
  16.         self.remainingfunc = remainingfunc
  17.         self.leftfunc = leftfunc
  18.         self.file_length = file_length
  19.         self.finflag = finflag
  20.         self.interval = interval
  21.         self.spewflag = spewflag
  22.         self.lastids = []
  23.         self.display()
  24.  
  25.     
  26.     def _rotate(self):
  27.         cs = self.choker.connections
  28.         for id in self.lastids:
  29.             for i in xrange(len(cs)):
  30.                 if cs[i].get_id() == id:
  31.                     return cs[i:] + cs[:i]
  32.                     continue
  33.             
  34.         
  35.         return cs
  36.  
  37.     
  38.     def collect_spew(self):
  39.         l = []
  40.         cs = self._rotate()
  41.         self.lastids = [ c.get_id() for c in cs ]
  42.         for c in cs:
  43.             rec = { }
  44.             rec['ip'] = c.get_ip()
  45.             if c.is_locally_initiated():
  46.                 rec['initiation'] = 'local'
  47.             else:
  48.                 rec['initiation'] = 'remote'
  49.             u = c.get_upload()
  50.             rec['upload'] = (int(u.measure.get_rate()), u.is_interested(), u.is_choked())
  51.             d = c.get_download()
  52.             rec['download'] = (int(d.measure.get_rate()), d.is_interested(), d.is_choked(), d.is_snubbed())
  53.             l.append(rec)
  54.         
  55.         return l
  56.  
  57.     
  58.     def display(self):
  59.         self.add_task(self.display, self.interval)
  60.         spew = []
  61.         if self.finflag.isSet():
  62.             status = {
  63.                 'upRate': self.upfunc(),
  64.                 'upTotal': self.uptotal() / 1048576.0 }
  65.             if self.spewflag.isSet():
  66.                 status['spew'] = self.collect_spew()
  67.             
  68.             self.statusfunc(status)
  69.             return None
  70.         
  71.         timeEst = self.remainingfunc()
  72.         if self.file_length > 0:
  73.             fractionDone = (self.file_length - self.leftfunc()) / float(self.file_length)
  74.         else:
  75.             fractionDone = 1
  76.         status = {
  77.             'fractionDone': fractionDone,
  78.             'downRate': self.downfunc(),
  79.             'upRate': self.upfunc(),
  80.             'upTotal': self.uptotal() / 1048576.0,
  81.             'downTotal': self.downtotal() / 1048576.0 }
  82.         if timeEst is not None:
  83.             status['timeEst'] = timeEst
  84.         
  85.         if self.spewflag.isSet():
  86.             status['spew'] = self.collect_spew()
  87.         
  88.         self.statusfunc(status)
  89.  
  90.  
  91.